/*
 * Niiuzu
 * Copyright (C) 2011  Thierry Nowak
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.partvoyage.client.sessionClient;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.maps.client.geocode.DirectionResults;
import com.partvoyage.client.mvp2.view.carte.bean.RouteSetBean;
import com.partvoyage.client.outil.PointSurLaCarte;
import com.partvoyage.client.service.compteproprietaire.CompteProprietaireBean;
import com.partvoyage.client.service.projet.ProjetBean;
import com.partvoyage.shared.InfoPointBean;

/**
 * Bulle mémoire disponible du côté client (au sens GWT) stockant les objets
 * nécessaires à l'image d'une session dans une servlet. Il s'agit d'un
 * singleton (une seule instance) afin d'assurer la cohérence des données entre
 * tous les presenters.
 */
public class SessionClient {

	private static SessionClient instance;

	private Boolean wikipediaActive = Boolean.FALSE;
	private Boolean photoPicassaActive = Boolean.FALSE;
	private ProjetBean projetBeanCourant;
	private InfoPointBean infoPointBeanCourant;
	// private User user;
	private CompteProprietaireBean compteProprietaire = new CompteProprietaireBean(
			Long.valueOf(1), "ludobou@gmail.com");
	private PointSurLaCarte sourcePourRoute = null;
	private RouteSetBean routeSetBean;
	private List<PointSurLaCarte> pointSurLaCartes = new ArrayList<PointSurLaCarte>();

	/**
	 * Construit une nouvelle instance de {@link SessionClient}.
	 */
	private SessionClient() {

	}

	public Boolean isSourcePourRoute() {
		return sourcePourRoute != null;
	}

	public PointSurLaCarte getSourcePourRoute() {
		return sourcePourRoute;
	}

	public void setSourcePourRoute(PointSurLaCarte sourcePourRoute) {
		this.sourcePourRoute = sourcePourRoute;
	}

	/**
	 * Récupère l'unique instance de {@link SessionClient}.
	 */
	public static SessionClient getInstance() {

		if (instance == null) {
			instance = new SessionClient();
		}
		return instance;
	}

	public ProjetBean getProjetBeanCourant() {
		return projetBeanCourant;
	}

	public void setProjetBeanCourant(ProjetBean projetBeanCourant) {
		this.projetBeanCourant = projetBeanCourant;
	}

	public InfoPointBean getInfoPointBeanCourant() {
		return infoPointBeanCourant;
	}

	public void setInfoPointBeanCourant(InfoPointBean infoPointBeanCourant) {
		this.infoPointBeanCourant = infoPointBeanCourant;
	}

	// public User getUser() {
	// return user;
	// }
	//
	// public void setUser(User user) {
	// this.user = user;
	// }

	/**
	 * JUnit - Écrase toutes les données sauvegardées jusqu'ici.
	 */
	static void clearAll() {
		instance = new SessionClient();
	}

	public CompteProprietaireBean getCompteProprietaire() {
		return compteProprietaire;
	}

	public void setCompteProprietaire(CompteProprietaireBean compteProprietaire) {
		this.compteProprietaire = compteProprietaire;
	}

	public void activateDesactivateWikipedia() {
		wikipediaActive = !wikipediaActive;
	}

	public Boolean estWikipediaActive() {
		return wikipediaActive;

	}

	public void activateDesactivatePhotoPicassa() {
		photoPicassaActive = !photoPicassaActive;
	}

	public Boolean estPhotoPicassaActive() {
		return photoPicassaActive;

	}

	public void addRoute(PointSurLaCarte source, PointSurLaCarte destination,
			DirectionResults directionResults) {
		if (routeSetBean == null) {
			routeSetBean = new RouteSetBean();
		}
		routeSetBean.addRoute(source, destination, directionResults);
	}

	public RouteSetBean getRouteSetBean() {
		return routeSetBean;
	}

	public void addPointSurLaCarte(PointSurLaCarte pointSurLaCarte) {
		if (pointSurLaCartes == null) {
			pointSurLaCartes = new ArrayList<PointSurLaCarte>();
		}
		pointSurLaCartes.add(pointSurLaCarte);
	}

	public void resetPointSurLaCarte() {
		pointSurLaCartes = new ArrayList<PointSurLaCarte>();
	}

	public List<PointSurLaCarte> getPointSurLaCartes() {
		return pointSurLaCartes;
	}

	public void setPointSurLaCartes(List<PointSurLaCarte> pointSurLaCartes) {
		this.pointSurLaCartes = pointSurLaCartes;
	}

}
